﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cmdLineParserModule;

namespace cmdLineParserModule
{
    /// <summary>
    /// Option class for marking bool attribute, usable with 'bool' or 'bool?' only
    /// </summary>
    public class optionBoolAttribute : optionParametrizedAttribute
    {
        /// <summary>
        /// Type that associated property must be of
        /// </summary>
        /// <returns>Accepted type of associated property</returns>
        internal override Type typeAccepted()
        {
            if (choiceRequired)
                return typeof(bool);
            else
                return typeof(bool?);
        }
        
        /// <summary>
        /// Generates bool object from string parameter 
        /// </summary>
        /// <param name="stringValue">Parameter value</param>
        /// <returns>Boolean object from string value</returns>
        internal override object createValueFromString(string stringValue)
        {
            switch (stringValue.ToLower())
            {
                case "true": return true;
                case "false": return false;
                default: throw new WrongUsageException("{0} is not correct bool value, use true or false.", stringValue);
            }
        }
    }
}
